﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using TERP.WaterClient.Common;
using System.Data;
using CommonUtils;

namespace TERP.WaterClient.DbServices
{
    public class CustomerService : BaseService
    {

        public CustomerService()
            : base()
        {
        }

        public DataSet Its_Customer_Get(
                        string strCusID,
						string strCusCode,
                        string strCusName,
                        string strOrgName,
						string strAddress
            )
        {
			string strCusIDConditionList = "";
			string strCusCodeConditionList = "";
			string strCusNameConditionList = "";
			string strOrgNameConditionList = "";
			string strAddressConditionList = "";

			if (!StringUtils.IsEmpty(strCusID))
			{
			    strCusIDConditionList = "=  " + strCusID;
			}
			if (!StringUtils.IsEmpty(strCusName))
			{
			    strCusNameConditionList = "like %" + strCusName + "%";
			}
			if (!StringUtils.IsEmpty(strCusCode))
			{
			    strCusCodeConditionList = "like %" + strCusCode + "%";
			}
            if (!StringUtils.IsEmpty(strAddress))
			{
			    strAddressConditionList = "like %" + strAddress + "%";
			}
			if (!StringUtils.IsEmpty(strOrgName))
			{
			    strOrgNameConditionList = "like %" + strOrgName + "%";
			}

			string strTId = SystemGlobal.Instance.GetNextTid();
			//
			try
			{
			DataSet mdsFinal = new DataSet();
			mdsFinal  = _dbService.Its_WaterCustomer_Get(
					  _strGwUserCode,
					  _strGwPassword,
					  strTId,
					  _strSessionId,
					  strCusIDConditionList,
					  strCusCodeConditionList,
			            strCusNameConditionList,
			            strOrgNameConditionList,
						strAddressConditionList
			      );
			    mdsFinal = TERP.Utils.CUtils.MyDSDecode(mdsFinal);
			    if (CMyDataSet.HasError(mdsFinal))
			    {
			        throw GenServiceException(mdsFinal);
			    }
			return mdsFinal;
			}
			catch (Exception ex)
			{
			    throw ex;
			}
        }

		public DataSet Its_Water_Customer_Create(
							 string strCusCode
						 , string strCusName
						 , string strOrgName
						 , string strAddress
						 , string strCusTel
						 , string strDebit
						 , string strNote
						 , string strNoVoCurrent
						 , string strCuocVoCurrent
			)
		{
					

			string strTId = SystemGlobal.Instance.GetNextTid();
			//
			try
			{
				DataSet mdsFinal = new DataSet();
				mdsFinal = _dbService.Its_Water_Customer_Create(
						  _strGwUserCode,
						  _strGwPassword,
						  strTId,
						  _strSessionId,
						  strCusCode
						 ,  strCusName
						 ,  strOrgName
						 ,  strAddress
						 ,  strCusTel
						 ,  strDebit
						 ,  strNote
						 ,  strNoVoCurrent
						 ,  strCuocVoCurrent
					  );
				mdsFinal = TERP.Utils.CUtils.MyDSDecode(mdsFinal);
				if (CMyDataSet.HasError(mdsFinal))
				{
					throw GenServiceException(mdsFinal);
				}
				return mdsFinal;
			}
			catch (Exception ex)
			{
				throw ex;
			}
		}

		public DataSet Its_Water_Customer_Update(
						string strCusID
							 ,string strCusCode
						 , string strCusName
						 , string strOrgName
						 , string strAddress
						 , string strCusTel
						 , string strDebit
						 , string strNote
						 , string strNoVoCurrent
						 , string strCuocVoCurrent
			)
		{


			string strTId = SystemGlobal.Instance.GetNextTid();
			//
			try
			{
				DataSet mdsFinal = new DataSet();
				mdsFinal = _dbService.Its_Water_Customer_Update(
						  _strGwUserCode,
						  _strGwPassword,
						  strTId,
						  _strSessionId,
						  strCusID
						  , strCusCode
						 , strCusName
						 , strOrgName
						 , strAddress
						 , strCusTel
						 , strDebit
						 , strNote
						 , strNoVoCurrent
						 , strCuocVoCurrent
					  );
				mdsFinal = TERP.Utils.CUtils.MyDSDecode(mdsFinal);
				if (CMyDataSet.HasError(mdsFinal))
				{
					throw GenServiceException(mdsFinal);
				}
				return mdsFinal;
			}
			catch (Exception ex)
			{
				throw ex;
			}
		}


		public DataSet Its_Water_Customer_Delete(
						string strCusID
			)
		{


			string strTId = SystemGlobal.Instance.GetNextTid();
			//
			try
			{
				DataSet mdsFinal = new DataSet();
				mdsFinal = _dbService.Its_Water_Customer_Delete(
						  _strGwUserCode,
						  _strGwPassword,
						  strTId,
						  _strSessionId,
						  strCusID
					  );
				mdsFinal = TERP.Utils.CUtils.MyDSDecode(mdsFinal);
				if (CMyDataSet.HasError(mdsFinal))
				{
					throw GenServiceException(mdsFinal);
				}
				return mdsFinal;
			}
			catch (Exception ex)
			{
				throw ex;
			}
		}
    }

}
